﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CoHSIN.Controllers
{
    public class HomeController : ApplicationController
    {

        public ActionResult Index(string page, string tab)
        {
            if (string.IsNullOrEmpty(page)) { page = Globals.getDefaultPageName(); }
            if (string.IsNullOrEmpty(tab)) { tab = Globals.getDefaultTabName(page); }

            string errMsg = ""; 

            if (!Globals.pageExists(page))
            {
                errMsg = "Page: \"" + page + "\" does not exist.";
            }
            else if (!Globals.tabExists(page, tab))
            {
                errMsg = "Tab: \"" + tab + "\" of Page: \"" + page + "\" does not exist.";
            }

            Models.Page _page = Globals.getPage(page);
            Models.Tab _tab = Globals.getTab(_page, tab);

            Models.PageTab PageTab = new Models.PageTab()
            {
                Page = _page,
                Tab = _tab
            };

            ViewData["PageTab"] = PageTab;

            if (errMsg != "") { ViewData["ErrorMessage"] = errMsg; }
            
            ViewData["currentPage"] = page.ToLower();
            //ViewData["Tabs"] = PageTab.Page.Tabs;

            return View();
        }

    }
}
